import java.util.Scanner;

public class NGuessNumber {
    private int[] arr = new int[4];
    private int[] playerArr = new int[4];
    private int a = 0;
    private int b = 0;

    public int[] generateAnswer() {
        this.a = 0;
        this.b = 0;
        int a, b, c, d;
        while (true) {
            a = (int) (Math.random() * 9);
            b = (int) (Math.random() * 9);
            c = (int) (Math.random() * 9);
            d = (int) (Math.random() * 9);
            if (a != b && a != c && a != d && b != c && b != d) {
                arr = new int[]{a, b, c, d};
                break;
            }
        }
        return arr;
    }

    public int[] getPlayerInput() {
        System.out.println("请输入四个数字,之间用空格隔开");
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < playerArr.length; i++) {
            playerArr[i] = sc.nextInt();
        }
        return playerArr;
    }

    public int[] compareGuessAnswer() {
        a = 0;
        b = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == playerArr[i]) {
                a++;
            }

            for (int j = 0; j < arr.length; j++) {
                if (i != j) {
                    if (arr[i] == playerArr[j]) {
                        b++;
                    }
                }
            }
        }

        System.out.println(a + "A" + b + "B");
        return new int[]{a, b};
    }

    public boolean isWin() {
        if (a == 4) {
            System.out.println("你赢了！");
        }
        return a == 4;
    }

    public int[] setArr(int[] r) {
        arr = r;
        return r;
    }


    public static void main(String[] args) {
        NGuessNumber n = new NGuessNumber();

        while(true){
            n.generateAnswer();
            while(!n.isWin()){
                n.getPlayerInput();
                n.compareGuessAnswer();
            }
            System.out.println("再玩一局？(输入y继续，其他退出)");
            Scanner sc = new Scanner(System.in);
            if (!sc.next().equals("y")){
                break;
            }
        }

    }
}
